{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Convert Tubes To PolyData"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook contains a few examples of how to call wrapped methods in itk and ITKTubeTK."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ITK and TubeTK must be installed on your system for this notebook to work.  Typically, this is accomplished by\n",
    "   > python -m pip install itk-tubetk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import itk\n",
    "from itk import TubeTK as ttk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Load the tubes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "PixelType = itk.F\n",
    "Dimension = 3\n",
    "ImageType = itk.Image[PixelType, Dimension]\n",
    "    \n",
    "# Read tre file\n",
    "TubeFileReaderType = itk.SpatialObjectReader[Dimension]\n",
    "    \n",
    "tubeFileReader = TubeFileReaderType.New()\n",
    "tubeFileReader.SetFileName(\"Data/MRI-Normals/Normal071-VascularNetwork.tre\")\n",
    "tubeFileReader.Update()\n",
    "\n",
    "tubes = tubeFileReader.GetGroup()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Generate the polydata representation of the tubes and save it to the file \"Tube.vtp\".\n",
    "\n",
    "The Tube.vtp file can be displayed by dragging-and-dropping it onto ParaView Glance:\n",
    "   https://kitware.github.io/paraview-glance/app/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "itkImageF4 not loaded from module TubeTK because of exception:\n",
      " module 'itk.TubeTKPython' has no attribute 'itkImageF4'\n",
      "vectoritkImageF4 not loaded from module TubeTK because of exception:\n",
      " module 'itk.TubeTKPython' has no attribute 'vectoritkImageF4'\n"
     ]
    }
   ],
   "source": [
    "ttk.WriteTubesAsPolyData.New(Input=tubes, FileName=\"Tube.vtp\").Update()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "WheelEnv",
   "language": "python",
   "name": "wheelenv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
